package com.example.easy.excel.demo.config;
//
//import com.github.xiaoymin.knife4j.spring.extension.OpenApiExtensionResolver;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Configurable;
//import org.springframework.context.annotation.Bean;
//import springfox.documentation.builders.ApiInfoBuilder;
//import springfox.documentation.builders.PathSelectors;
//import springfox.documentation.builders.RequestHandlerSelectors;
//import springfox.documentation.service.ApiInfo;
//import springfox.documentation.service.Contact;
//import springfox.documentation.spi.DocumentationType;
//import springfox.documentation.spring.web.plugins.Docket;
//import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;
//
//@Configurable
//@EnableSwagger2WebMvc
//@Slf4j
//public class Knife4jjConfig {
//
////    private ApiInfo adminApiInfo() {
////        return new ApiInfoBuilder()
////                .title("Easy-Excel-Demo-Api文档")
////                .description("Easy-Excel学习")
////                .version("0.0.1")
////                .build();
////    }
////
////    private ApiInfo webApiInfo() {
////        return new ApiInfoBuilder()
////                .title("Eric-SpringBoot整合Knife4j-API文档")
////                .description("本文档描述了SpringBoot如何整合Knife4j")
////                .version("1.0")
////                .contact(new Contact("Eric", "https://blog.csdn.net/weixin_47316183?type=blog", "ericsyn@foxmail.com"))
////                .build();
////    }
//
////    /**
////     * 第一组：api
////     * @return
////     */
////    @Bean
////    public Docket webApiConfig() {
////        List<Parameter> pars = new ArrayList<>();
////        ParameterBuilder tokenPar = new ParameterBuilder();
////        tokenPar.name("userId")
////                .description("用户token")
////                //.defaultValue(JwtHelper.createToken(1L, "admin"))
////                .defaultValue("1")
////                .modelRef(new ModelRef("string"))
////                .parameterType("header")
////                .required(false)
////                .build();
////        pars.add(tokenPar.build());
////
////        Docket webApi = new Docket(DocumentationType.SWAGGER_2)
////                .groupName("用户端接口")
////                .apiInfo(webApiInfo())
////                .select()
////                //只显示api路径下的页面
////                .apis(RequestHandlerSelectors.basePackage("com.eric.springbootknife4j"))
////                .paths(PathSelectors.regex("/api/.*"))
////                .build()
////                .globalOperationParameters(pars);
////        return webApi;
////    }
////
////    /**
////     * 第二组：admin
////     * @return
////     */
////    @Bean
////    public Docket adminApiConfig() {
////        List<Parameter> pars = new ArrayList<>();
////        ParameterBuilder tokenPar = new ParameterBuilder();
////        tokenPar.name("adminId")
////                .description("用户token")
////                .defaultValue("1")
////                .modelRef(new ModelRef("string"))
////                .parameterType("header")
////                .required(false)
////                .build();
////        pars.add(tokenPar.build());
////
////        Docket adminApi = new Docket(DocumentationType.SWAGGER_2)
////                .groupName("后台接口")
////                .apiInfo(adminApiInfo())
////                .select()
////                //只显示admin路径下的页面
////                .apis(RequestHandlerSelectors.basePackage("com.eric.springbootknife4j"))
////                .paths(PathSelectors.regex("/admin/.*"))
////                .build()
////                .globalOperationParameters(pars);
////        return adminApi;
////    }
//
//    /**
//     * 【重要】指定Controller包路径
//     */
//    private static final String BASE_PACKAGE = "com.example.easy.excel.demo.config.controller";
//    /**
//     * 组名
//     */
//    private static final String GROUP_NAME = "Easy-Excel-Demo";
//    /**
//     * 主机名
//     */
//    private static final String HOST = "https://www.baidu.com";
//    /**
//     * 标题
//     */
//    private static final String TITLE = "Easy-Excel-Demo-在线Api文档";
//    /**
//     * 简介
//     */
//    private static final String DESCRIPTION = "Easy-Excel-Demo-学习";
//    /**
//     * 服务条款URL
//     */
//    private static final String TERMS_OF_SERVICE_URL = "http://www.apache.org/licenses/LICENSE-2.0";
//    /**
//     * 联系人
//     */
//    private static final String CONTACT_NAME = "lxs";
//    /**
//     * 联系网址
//     */
//    private static final String CONTACT_URL = "lxs";
//    /**
//     * 联系邮箱
//     */
//    private static final String CONTACT_EMAIL = "luxiusheng@163.com";
//    /**
//     * 版本号
//     */
//    private static final String VERSION = "0.0.1";
//
//    //    @Autowired
////    private OpenApiExtensionResolver openApiExtensionResolver;
////    private OpenApiExtensionResolver openApiExtensionResolver;
////
////    public Knife4jjConfig() {
////        log.debug("创建配置类对象：Knife4jConfiguration");
////    }
////
////    @Autowired
////    public Knife4jjConfig(OpenApiExtensionResolver openApiExtensionResolver) {
////        this.openApiExtensionResolver = openApiExtensionResolver;
////    }
//
//    @Bean
//    public Docket docket() {
//        return new Docket(DocumentationType.SWAGGER_2)
//                .host(HOST)
//                .apiInfo(apiInfo())
//                .groupName(GROUP_NAME)
//                .select()
//                .apis(RequestHandlerSelectors.basePackage(BASE_PACKAGE))
//                .paths(PathSelectors.any())
//                .build();
////                .extensions(openApiExtensionResolver.buildExtensions(GROUP_NAME));
//    }
//
//    private ApiInfo apiInfo() {
//        return new ApiInfoBuilder()
//                .title(TITLE)
//                .description(DESCRIPTION)
//                .termsOfServiceUrl(TERMS_OF_SERVICE_URL)
//                .contact(new Contact(CONTACT_NAME, CONTACT_URL, CONTACT_EMAIL))
//                .version(VERSION)
//                .build();
//    }
//
////
//}

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

@Configuration
@EnableSwagger2WebMvc
public class Knife4jConfig {

    @Bean
    public Docket docket() {
        String groupName = "用户管理";
        Docket docket = new Docket(DocumentationType.SWAGGER_2)
                .host("https://www.baidu.com")
                .apiInfo(apiInfo())
                .groupName(groupName)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.example.easy.excel.demo.controller"))
                .paths(PathSelectors.any())
                .build();

        return docket;
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("swagger-bootstrap-ui RESTful APIs")
                .description("swagger-bootstrap-ui")
                .termsOfServiceUrl("http://www.nucarf.com")
                .contact("nucarf@mail.com")
                .version("9.9")
                .build();
    }
}